package com.lms.thread.demo3;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author: 李孟帅
 * @CreateTime: 2020-01-19 10:03
 * @Description: ${Description}
 */
public class LockTest {
    private Integer syncNum=0;
    private Lock lock=new ReentrantLock();
    public void lock(){
        lock.lock();
        System.out.println(Thread.currentThread().getName() + ":begin");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        syncNum++;
        System.out.println("线程：" + Thread.currentThread().getName() + ",syncNum:" + syncNum);
        System.out.println(Thread.currentThread().getName() + ":end");
        lock.unlock();
    }
}
